package marking.liu.pojo.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import springfox.documentation.annotations.ApiIgnore;

import java.io.Serializable;

// Serializable是标识接口 说明该类是可序列化类
@Data
public class Result<R> implements Serializable {
    private static final int SUCCESS_CODE = 1;
    private static final int ERROR_CODE = 0;

    private int code;
    private String msg;
    private R data;

//    private Result(int code, String msg, R data) {
//        this.code = code;
//        this.msg = msg;
//        this.data = data;
//    }
//
//    private Result(int code, String msg) {
//        this.code = code;
//        this.msg = msg;
//    }
//
//    private Result(int code, R data) {
//        this.code = code;
//        this.data = data;
//    }

    public static <R> Result<R> ok(){
        Result<R> result = new Result<R>();
        result.code = SUCCESS_CODE;
        result.msg = "success";
        return result;
    }
    public static <R> Result<R> ok(String msg){
        Result<R> result = new Result<R>();
        result.code = SUCCESS_CODE;
        result.msg = msg;
        return result;
    }
    public static <R> Result<R> ok(R data){
        Result<R> result = new Result<R>();
        result.code = SUCCESS_CODE;
        result.data = data;
        return result;
    }
    public static <R> Result<R> ok(String msg, R data){
        Result<R> result = new Result<R>();
        result.code = SUCCESS_CODE;
        result.msg = msg;
        result.data = data;
        return result;
    }

    public static <R> Result<R> error(){
        Result<R> result = new Result<R>();
        result.code = ERROR_CODE;
        result.msg = "error";
        return result;
    }
    public static <R> Result<R> error(String msg){
        Result<R> result = new Result<R>();
        result.code = ERROR_CODE;
        result.msg = msg;
        return result;
    }
}
